﻿using FluentNHibernate.Mapping;
using Products.Domain.Products;
using Products.Domain.SubProducts;

namespace Product.Infrastructure.Persistence.Products
{


    //good practice but I don't have a time... :) 
    //public class EnittyMapping<T> : ClassMap<T>  where T : Entity
    //{
    //    public EnittyMapping()
    //    {
    //        Map(x=>x.Id).....
    //    }
    //}

    public class ProduceMappings : ClassMap<Produce>
    {
        public ProduceMappings()
        {
            Table("Produces");
            Id(x => x.Id).GeneratedBy.Assigned();
            Map(x => x.ProductName).Not.Nullable();
            Map(x => x.Description).Not.Nullable();
            Map(x => x.Price).Not.Nullable();
            Map(x => x.AdditionalDescription);

            HasMany(x => x.SubProducts).Access.CamelCaseField(Prefix.Underscore).Cascade.AllDeleteOrphan();
        }
    }

    public class SubProductMappings : ClassMap<SubProduct>
    {
        public SubProductMappings()
        {
            Table("SUB_PRODUCTS");
            Id(x => x.Id).GeneratedBy.Assigned();
            Map(x => x.Name).Not.Nullable();
        }
    }
}
